package com.example.manualManagement.controller;

import com.example.manualManagement.entity.Department;
import com.example.manualManagement.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class DepartmentCtrl {

    @Autowired
    private DepartmentService dpService;


    @RequestMapping(value = "/department/delete", method = RequestMethod.POST)
    public String delete(Integer dpID) {
        int result = dpService.delete(dpID);
        if(result >= 1){
            return "删除成功";
        }else{
            return "删除失败";
        }
    }

    @RequestMapping(value = "/department/update", method = RequestMethod.POST)
    @ResponseBody
    public String update(Department dp) {
        int result= dpService.Update(dp);
        if (result >= 1) {
            return "修改成功";
        } else {
            return "修改失败";
        }

    }

    @RequestMapping(value = "/department/insert", method = RequestMethod.POST)
    public String insert(Department dp) {
        //System.out.println(dp.getDpID());
        int result = dpService.insertUser(dp);
        if(result >= 1){
            return "添加成功";
        }else{
            return "添加失败";
        }
    }

    @RequestMapping("/department/ListDepartment")
    @ResponseBody
    public List<Department> ListDepartment() {
        return dpService.ListUser();
    }

    @RequestMapping("/department/ListByName")
    @ResponseBody
    public List<Department> ListDepartmentByName(String dpName) {
        return dpService.findByName(dpName);
    }


    @RequestMapping("/department/page")
    @ResponseBody
    public List<Department> page(Integer page){
        return  dpService.queryPage(page);
    }

    @RequestMapping("/department/rows")
    @ResponseBody
    public int rows(){
        return (int) dpService.getRowCount();
    }
}
